/*
 *  $Id: OceanGrip.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

namespace Ragima.Cards001.Water.Spells {
    public class OceanGrip: TargetEnchantmentCard<Creature> {
        public OceanGrip(): base("001_w_s_ocean_grip") {
            Level = CompleteLevel.ReadyForTest;
            Version = 0;
            Element = ElementType.Water;
            Value = 100;
            Target = new CreatureTarget(GetTargetPhrase(), true, false, CreatureTarget.IsAquatic);
            AddManaCost(ElementType.Water, 5);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new OceanGripAffect();
        }

        private class OceanGripAffect: EnchantmentAffect<OceanGrip> {
            public OceanGripAffect() {
                Add(new TimeAffect(1, TimePhase.OwnOffence));
            }

            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnHit += DoHit;
            }

            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnHit -= DoHit;
            }

            private void DoHit(Creature hitter, AbstractObject target, int damage) {
                Creature cr = target as Creature;
                if (cr == null || cr.IsAquatic || cr.IsDeath || damage == 0) return;
                int h = Math.Min(hitter.MaxHealth, cr.MaxHealth);
                cr.DamageBy(NewDamage(DamageType.PhysicalAttack, h));
                hitter.DamageBy(NewDamage(DamageType.PhysicalAttack, h));
            }
        }
    }
}
